public with sharing class CCIRCaseEmailsComponentController extends CaseEmailsComponentController {	
    public Id parentCaseId {get; set;}
    public string selectedCaseNumber {get;set;}
    
    //get list of email messages for all related cases.
    public override List<cEmail> getCaseEmailMessage(){        
           list<cEmail> caseEmails = new list<cEmail>();
            Id searchCaseId;  
		    if(parentCaseId != null)
			  searchCaseId = parentCaseId ; 
			else
			  searchCaseId = emailCase.Id; 

           			         
           for(EmailMessage email : [Select Id,Parent.Id, Parent.CaseNumber,Parent.RecordType.Name,Parent.Owner.Name, Parent.Status, MessageDate, Status, Subject, ToAddress, Incoming,TextBody,HtmlBody,HasAttachment From EmailMessage  where  parent.ParentId = :searchCaseId or parentid= :searchCaseId order by LastModifiedDate desc LIMIT 100 ])
           {
             cEmail tempcEmail= new cEmail();
             tempcEmail.emailId 		= email.Id;
             tempcEmail.status			= emailStatus.get(integer.valueof(email.Status));
             tempcEmail.subject			= email.subject;
             tempcEmail.toaddress		= email.toaddress;
             tempcEmail.caserecordType 	= email.Parent.RecordType.Name;
             tempcEmail.caseOwner      	= email.Parent.Owner.Name;
             tempcEmail.caseStatus     	= email.Parent.Status; 
             tempcEmail.CaseNumber		= email.Parent.CaseNumber;
             tempcEmail.parentCaseId    = email.Parent.Id;
             
             //if the case is current selected case and sel..
             //mark the current email from the selected case..
             if(email.Parent.Id ==  emailCase.Id)
                 tempcEmail.selectedCase =  true;
             else
                 tempcEmail.selectedCase =  false;
                     
             if(email.messageDate!= null ) 
                tempcEmail.messageDate	= email.messageDate.format();
                
             tempcEmail.hasAttachment 	= email.HasAttachment;
             if(email.TextBody != null)   { 
	             if( email.TextBody.Length()> 80)
	                 tempcEmail.Body 	= email.TextBody.SubString(0,77) + '...';
	             else
	                tempcEmail.Body 	= email.TextBody;
	              
              } 
             else
                {
	             if(email.HtmlBody != null && email.HtmlBody.Length()> 80)
	                 tempcEmail.Body 	= email.HtmlBody.SubString(0,77) + '...';
	             else
	                tempcEmail.Body 	= email.HtmlBody;
                
                }   
       	     tempcEmail.Incoming	= email.Incoming;
			 //Add to list              
             caseEmails.add(tempcEmail);
           }
          
           if(caseEmails.size() == 0 ) 
              return null;
           else 
              return caseEmails;

    }
}